package cn.pugle.benchmark;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.Collection;
import java.util.concurrent.TimeUnit;

/**
 * @author tzp
 * @since 2018/12/23
 */
@Warmup(iterations = 5)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class FirstJMH {

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(FirstJMH.class.getSimpleName())
                .forks(1)
                .build();
        Collection<RunResult> results = new Runner(options).run();
        System.out.println(results.iterator().next());
    }

    @Benchmark
    @Measurement(iterations = 5)
    public void benchmarkReplace() {
        MyBenchMark.replace();
    }

    @Benchmark
    @Measurement(iterations = 5)
    public void benchmarkFormat() {
        MyBenchMark.format();
    }
}
